<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('修改职工信息')"/>
    <th:block th:include="include :: ztree-css"/>
    <th:block th:include="include :: select2-css"/>
</head>
<body class="white-bg">
<div class="wrapper wrapper-content animated fadeInRight ibox-content">
    <form class="form-horizontal m" id="form-role-edit" th:object="${teacher}">
        <input id="roleId" name="studentId" th:field="*{teacherId}" type="hidden"/>
        <div class="form-group">
            <label class="col-sm-3 control-label ">职工名称：</label>
            <div class="col-sm-8">
                <input class="form-control" id="teacherName" name="teacherName" required th:field="*{teacherName}"
                       type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label ">技术专长：</label>
            <div class="col-sm-8">
                <input class="form-control" id="teacherTechnical" name="teacherTechnical" required
                       th:field="*{teacherTechnical}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">所在系号：</label>
            <div class="col-sm-8">
                <select class="form-control" id="departmentId" name="departmentId"
                        required th:field="*{departmentId}" th:with="type=${@dept.getDepartmentId()}">
                    <option th:each="dept : ${type}" th:text="${dept.deptName}" th:value="${dept.deptId}"></option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">出生日期：</label>
            <div class="col-sm-8">
                <input class="form-control" id="teacherBirthday" name="teacherBirthday" placeholder="年-月-日"
                       required th:field="*{teacherBirthday}" type="text">
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">职工性别：</label>
            <div class="col-sm-8">
                <select class="form-control" id="teacherSex" name="teacherSex" required th:field="*{teacherSex}">
                    <option value="0">男</option>
                    <option value="1">女</option>
                    <option value="2">未知</option>
                </select>
            </div>
        </div>
        <div class="form-group">
            <label class="col-sm-3 control-label">职工职称：</label>
            <div class="col-xs-8">
                <select class="form-control" id="post" required th:field="*{teacherTitle}">
                    <option th:disabled="${post.status == '1'}" th:each="post:${posts}" th:text="${post.postName}"
                            th:value="${post.postId}"></option>
                </select>
            </div>
        </div>
    </form>
</div>
<th:block th:include="include :: footer"/>
<th:block th:include="include :: ztree-js"/>
<th:block th:include="include :: datetimepicker-js"/>
<th:block th:include="include :: select2-js"/>
<script type="text/javascript">
    $(function () {
        $("#studentBirthday").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
    });


    function edit() {
        var teacherId = $("input[name='teacherId']").val();
        var teacherName = $("input[name='teacherName']").val();
        var teacherTechnical = $("input[name='teacherTechnical']").val();
        var teacherBirthday = $("input[name='teacherBirthday']").val();
        var teacherSex = $("#teacherSex").val();
        var departmentId = $("#departmentId").val();
        var teacherTitle = $.form.selectSelects("post");
        $.ajax({
            cache: true,
            type: "POST",
            url: ctx + "project/teacher/updateTeacher",
            data: {
                "teacherId": teacherId,
                "teacherName": teacherName,
                "teacherTechnical": teacherTechnical,
                "teacherBirthday": teacherBirthday,
                "teacherSex": teacherSex,
                "departmentId": departmentId,
                "teacherTitle": teacherTitle
            },
            async: false,
            error: function (request) {
                $.modal.alertError("系统错误");
            },
            success: function (data) {
                $.operate.successCallback(data);
            }
        });
    }

    function submitHandler() {
        if ($.validate.form()) {
            edit();
        }
    }

    /*用户管理-新增-选择部门树*/
    function selectDeptTree() {
        var treeId = $("#treeId").val();
        var deptId = $.common.isEmpty(treeId) ? "100" : $("#treeId").val();
        var url = ctx + "system/dept/selectDeptTree/" + deptId;
        var options = {
            title: '选择院系',
            width: "380",
            url: url,
            callBack: doSubmit
        };
        $.modal.openOptions(options);
    }

    function doSubmit(index, layero) {
        var tree = layero.find("iframe")[0].contentWindow.$._tree;
        if ($.tree.notAllowParents(tree)) {
            var body = layer.getChildFrame('body', index);
            $("#treeId").val(body.find('#treeId').val());
            $("#treeName").val(body.find('#treeName').val());
            layer.close(index);
        }
    }
</script>
</body>
</html>
